package client.gui;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.*;

import client.Client;
import client.game.world.map.Region;


public class GameFrame extends JFrame implements MouseListener {

	private static final long serialVersionUID = 6729194140076463621L;
	private int FPS = 20;
	private int GAME_SPEED = 20;
	private GameCanvas canvas;

	public int getFPS() {
		return FPS;
	}

	public GameFrame(String title, int width, int height) {
		super(title);
		canvas = new GameCanvas();
		add(canvas);
		setSize(width, height);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		canvas.addMouseListener(this);
		System.out.println(Toolkit.getDefaultToolkit().getBestCursorSize(17,18));
		Image cursor = Toolkit.getDefaultToolkit().getImage("pointer.gif");
		setCursor(Toolkit.getDefaultToolkit().createCustomCursor(cursor, new Point(0,0), "cursor"));
		setVisible(true);
		GameLoop loop = new GameLoop(this, GAME_SPEED, FPS);
		loop.setRunning(true);
		new Thread(loop).start();
	}

	public void updateGame() {
	}

	@Override
	public void paint(Graphics g) {
		canvas.repaint();
	}

	@Override
	public void update(Graphics g) {
		paint(g);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		int x = (arg0.getX() - Client.getPlayer().getRegionOffsetX())/32;
		int y = (arg0.getY() - Client.getPlayer().getRegionOffsetX())/32;
		Region region = Client.getWorld().getWorldMap().getRegion(0, 0);
		region.pathFinding.findPath(region.getTile(0, 0), region.getTile(x,y));
		region.getTile(0,0).highlighted = true;
		region.getTile(x,y).highlighted = true;
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {}

	@Override
	public void mouseExited(MouseEvent arg0) {}

	@Override
	public void mousePressed(MouseEvent arg0) {
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {}


}
